import { local } from '@/utils/jcore/storage'

// app vuex
const state = {
  selectRouteName: '',
  userInfo: {},
  menuList: [],
  isCollapse: local.get('sidebarisCollapseStatus') == 1
}

const mutations = {
  setSelectRouteName: (store, name) => {
    store.selectRouteName = name
  },
  setUserInfo: (store, data) => {
    store.userInfo = data
  },
  setMenuList: (store, data) => {
    store.menuList = data
  },
  TOGGLE_SIDEBAR: (state) => {
    state.isCollapse = !state.isCollapse
    if (state.isCollapse) {
      local.set('sidebarisCollapseStatus', 1)
    } else {
      local.set('sidebarisCollapseStatus', 0)
    }
  }
}

const actions = {
  setSelectRouteName({ commit }, name) {
    commit('setSelectRouteName', name)
  },
  setUserInfo({ commit }, data) {
    commit('setUserInfo', data)
  },
  setMenuList({ commit }, data) {
    commit('setMenuList', data)
  },
  toggleSideBar({ commit }) {
    commit('TOGGLE_SIDEBAR')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
